package edu.udo.sopra10.chaturaji.gui.util;

import java.awt.GridBagConstraints;
import java.awt.Insets;

/**
 * Utility class to speed up the work with {@link GridBagConstraints}. It
 * allows a single constrains object to be reused.
 * 
 * @author Patrick Westerhoff
 */
public class SimpleGridBagConstraints extends GridBagConstraints
{
	private static final long serialVersionUID = -6459500704029559602L;
	
	/**
	 * Constructs an empty SimpleGridBagConstraints object.
	 */
	public SimpleGridBagConstraints ()
	{
		super();
	}
	
	/**
	 * Constructs a SimpleGridBagConstraints object with the given values.
	 * 
	 * @param gridx the initial gridx value.
	 * @param gridy the initial gridy value.
	 * @param gridwidth the initial gridwidth value.
	 * @param gridheight the initial gridheight value.
	 * @param weightx the initial weightx value.
	 * @param weighty the initial weighty value.
	 * @param anchor the initial anchor value.
	 * @param fill the initial fill value.
	 * @param insets the initial insets value.
	 * @param ipadx the initial ipadx value.
	 * @param ipady the initial ipady value.
	 */
	public SimpleGridBagConstraints ( int gridx, int gridy, int gridwidth, int gridheight, double weightx,
			double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady )
	{
		super( gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, insets, ipadx, ipady );
	}
	
	/**
	 * Updates the gridx value and returns the modified object.
	 * 
	 * @param gridX the new gridx value.
	 * @return the modified SimpleGridBagConstraints object.
	 */
	public SimpleGridBagConstraints setGridX ( int gridX )
	{
		this.gridx = gridX;
		return this;
	}
	
	/**
	 * Updates the gridy value and returns the modified object.
	 * 
	 * @param gridY the new gridy value.
	 * @return the modified SimpleGridBagConstraints object.
	 */
	public SimpleGridBagConstraints setGridY ( int gridY )
	{
		this.gridy = gridY;
		return this;
	}
	
	/**
	 * Updates both the gridx and the gridy values and returns the modified
	 * object.
	 * 
	 * @param gridX the new gridx value.
	 * @param gridY the new gridy value.
	 * @return the modified SimpleGridBagConstraints object.
	 */
	public SimpleGridBagConstraints setGrid ( int gridX, int gridY )
	{
		this.gridx = gridX;
		this.gridy = gridY;
		return this;
	}
	
	/**
	 * Updates the internal padding and returns the modified object.
	 * 
	 * @param padX the new internal x-padding.
	 * @param padY the new internal y-padding.
	 * @return the modified SimpleGridBagConstraints object.
	 */
	public SimpleGridBagConstraints setPadding ( int padX, int padY )
	{
		this.ipadx = padX;
		this.ipady = padY;
		return this;
	}
	
	/**
	 * Updates the insets and returns the modified object.
	 * 
	 * @param top the inset from the top.
	 * @param right the inset from the right.
	 * @param bottom the inset from the bottom.
	 * @param left the inset from the left.
	 * @return the modified SimpleGridBagConstraints object.
	 */
	public SimpleGridBagConstraints setInsets ( int top, int right, int bottom, int left )
	{
		if ( this.insets != null )
		{
			this.insets.top = top;
			this.insets.right = right;
			this.insets.bottom = bottom;
			this.insets.left = left;
		}
		else
			this.insets = new Insets( top, left, bottom, right );
		return this;
	}
}